home *** CD-ROM | disk | FTP | other *** search
/ Revista do CD-ROM 97 / CD-ROM 97 / CD-ROM 97.iso / internet / ghostzilla / ghsetup.exe / chrome / toolkit.jar / content / global / bindings / textbox.xml < prev    next >
Encoding:
Extensible Markup Language  |  2002-04-13  |  7.6 KB  |  168 lines

  1. <?xml version="1.0"?>
  2.  
  3. <!DOCTYPE window [
  4.   <!ENTITY % textcontextDTD SYSTEM "chrome://global/locale/textcontext.dtd" >
  5.   %textcontextDTD;
  6. ]>
  7.  
  8. <bindings id="textboxBindings"
  9.    xmlns="http://www.mozilla.org/xbl"
  10.    xmlns:html="http://www.w3.org/1999/xhtml"
  11.    xmlns:xul="http://www.mozilla.org/keymaster/gatekeeper/there.is.only.xul"
  12.    xmlns:xbl="http://www.mozilla.org/xbl">
  13.  
  14.   <binding id="textbox" extends="xul:box">
  15.     <resources>
  16.       <stylesheet src="chrome://global/skin/textbox.css"/>
  17.     </resources>
  18.     
  19.     <content>
  20.       <xul:hbox class="textbox-input-box" flex="1">
  21.         <html:input class="textbox-input" flex="1" anonid="input"
  22.                     xbl:inherits="onfocus,onblur,value,type,maxlength,disabled,size,readonly,tabindex"/>
  23.       </xul:hbox>
  24.     </content>
  25.     
  26.     <implementation>
  27.       <field name="mInputField">null</field>
  28.       
  29.       <property name="inputField" readonly="true">
  30.         <getter><![CDATA[
  31.           if (!this.mInputField)    
  32.             this.mInputField = document.getAnonymousElementByAttribute(this, "anonid", "input");
  33.           return this.mInputField;
  34.         ]]></getter>
  35.       </property>
  36.       
  37.       <property name="value"      onset="this.inputField.value = val; return val;"
  38.                                   onget="return this.inputField.value;"/>
  39.       <property name="type"       onset="this.inputField.type = val; return val;"
  40.                                   onget="return this.inputField.type;"/>
  41.       <property name="maxlength"  onset="this.inputField.maxlength = val; return val;"
  42.                                   onget="return this.inputField.maxlength;"/>
  43.       <property name="disabled"   onset="this.inputField.disabled = val;
  44.                                          if (val) this.setAttribute('disabled', 'true');
  45.                                          else this.removeAttribute('disabled'); return val;"
  46.                                   onget="return this.inputField.disabled;"/>
  47.       <property name="size"       onset="this.inputField.size = val; return val;"
  48.                                   onget="return this.inputField.size;"/>
  49.       <property name="readonly"   onset="this.inputField.readonly = val;
  50.                                          if (val) this.setAttribute('disabled', 'true');
  51.                                          else this.removeAttribute('disabled'); return val;"
  52.                                   onget="return this.inputField.readonly;"/>
  53.                             
  54.       <method name="select">
  55.         <body>
  56.           this.inputField.select();
  57.         </body>
  58.       </method>
  59.  
  60.       <property name="controllers"    readonly="true" onget="return this.inputField.controllers"/>
  61.       <property name="textLength"     readonly="true" onget="return this.inputField.textLength;"/>
  62.       <property name="selectionStart" onset="this.inputField.selectionStart = val; return val;"
  63.                                       onget="return this.inputField.selectionStart;"/>
  64.       <property name="selectionEnd"   onset="this.inputField.selectionEnd = val; return val;"
  65.                                       onget="return this.inputField.selectionEnd;"/>
  66.      
  67.       <field name="suppressFocusBlur">false</field>
  68.  
  69.       <method name="setSelectionRange">
  70.         <parameter name="aSelectionStart"/>
  71.         <parameter name="aSelectionEnd"/>
  72.         <body>
  73.           this.inputField.setSelectionRange( aSelectionStart, aSelectionEnd );
  74.         </body>
  75.       </method>
  76.  
  77.       <constructor action="var str = this.boxObject.getProperty('value'); 
  78.                                                 if (str) {
  79.                                                   this.inputField.value=str;
  80.                                                   this.boxObject.removeProperty('value');
  81.                                                 }"/>
  82.       <destructor action="if (this.inputField.value) this.boxObject.setProperty('value', this.inputField.value);"/>
  83.    
  84.     </implementation>
  85.     
  86.     <handlers>
  87.       <handler event="focus" phase="capturing">
  88.       <![CDATA[
  89.         if (!this.hasAttribute('focused')) {
  90.           this.setAttribute('focused','true');
  91.           this.suppressFocusBlur = true;
  92.           if (document.commandDispatcher.focusedElement != this.inputField) 
  93.             this.inputField.focus();
  94.           this.suppressFocusBlur = false;
  95.         }
  96.       ]]>
  97.       </handler>
  98.       
  99.       <handler event="blur" phase="capturing">
  100.       <![CDATA[
  101.         if (!this.suppressFocusBlur && this.hasAttribute('focused')) {
  102.           this.removeAttribute('focused');
  103.         }
  104.       ]]>
  105.       </handler>
  106.     </handlers>    
  107.   </binding>
  108.  
  109.   <binding id="textarea" extends="chrome://global/content/bindings/textbox.xml#textbox">
  110.     <content>
  111.       <xul:hbox class="textbox-input-box" flex="1">
  112.         <html:textarea class="textbox-textarea" flex="1" anonid="input"
  113.                        xbl:inherits="onfocus,onblur,value,disabled,rows,cols,readonly,wrap"/>
  114.       </xul:hbox>
  115.     </content>
  116.   </binding>
  117.  
  118.   <binding id="input-box">
  119.     <content context="_child">
  120.       <children/>
  121.       <xul:menupopup onpopupshowing="this.parentNode.focus(); this.parentNode.doPopupItemEnabling(this);">
  122.         <xul:menuitem label="&undoCmd.label;" accesskey="&undoCmd.accesskey;" cmd="cmd_undo"
  123.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_undo');              
  124.                                  controller.doCommand('cmd_undo');"/>
  125.         <xul:menuseparator/>
  126.         <xul:menuitem label="&cutCmd.label;" accesskey="&cutCmd.accesskey;" cmd="cmd_cut"
  127.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_cut');
  128.                                  controller.doCommand('cmd_cut');"/>
  129.         <xul:menuitem label="©Cmd.label;" accesskey="©Cmd.accesskey;" cmd="cmd_copy"
  130.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_copy');
  131.                                  controller.doCommand('cmd_copy');"/>
  132.         <xul:menuitem label="&pasteCmd.label;" accesskey="&pasteCmd.accesskey;" cmd="cmd_paste"
  133.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_paste');
  134.                       controller.doCommand('cmd_paste');"/>
  135.         <xul:menuitem label="&deleteCmd.label;" accesskey="&deleteCmd.accesskey;" cmd="cmd_delete"
  136.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_delete');
  137.                                  controller.doCommand('cmd_delete');"/>
  138.         <xul:menuseparator/>
  139.         <xul:menuitem label="&selectAllCmd.label;" accesskey="&selectAllCmd.accesskey;" cmd="cmd_selectAll"
  140.                       oncommand="var controller = document.commandDispatcher.getControllerForCommand('cmd_selectAll');
  141.                                  controller.doCommand('cmd_selectAll');"/>
  142.       </xul:menupopup>
  143.     </content>
  144.  
  145.     <implementation>
  146.       <method name="doPopupItemEnabling">
  147.         <parameter name="popupNode"/> 
  148.         <body>
  149.           <![CDATA[
  150.             var children = popupNode.childNodes;
  151.             for (var i = 0; i < children.length; i++) {              
  152.               var command = children[i].getAttribute("cmd");
  153.               if (command) {
  154.                 var controller = document.commandDispatcher.getControllerForCommand(command);
  155.                 var enabled = controller.isCommandEnabled(command);
  156.                 if (enabled)
  157.                   children[i].removeAttribute("disabled");
  158.                 else
  159.                   children[i].setAttribute("disabled", "true");               
  160.               }
  161.             }
  162.           ]]>
  163.         </body>
  164.       </method>
  165.     </implementation>
  166.   </binding>
  167.   
  168. </bindings>